﻿@using Stardust.Data.Deployment;
@using Stardust.Data.Nodes;
@{
    var obj = Model as Object;
    var path = Context.Request.Path + "";
    var nodeId = Context.Request.Query["nodeId"].ToInt(0);
    if (nodeId == 0 && path.EqualIgnoreCase("/Nodes/Node", "/Nodes/Node/Detail", "/Nodes/Node/Edit"))
    {
        nodeId = Context.Request.Query["Id"].ToInt(0);
    }

    var start = Context.Request.Query["dtStart"].ToDateTime();
    var end = Context.Request.Query["dtEnd"].ToDateTime();
    if (end.Year < 2000) end = Context.Request.Query["dtEnd2"].ToDateTime().AddSeconds(1);

    var node = Node.FindByID(nodeId) ?? new Node();

    var dic = new Dictionary<String, Object>();
    dic[node.Name + ""] = "/Nodes/Node/Edit?Id=" + nodeId;
    dic["在线"] = "/Nodes/NodeOnline?nodeId=" + nodeId;
    dic["历史"] = "/Nodes/NodeHistory?nodeId=" + nodeId;
    dic["命令"] = "/Nodes/NodeCommand?nodeId=" + nodeId;
    dic["性能"] = "/Nodes/NodeData?nodeId=" + nodeId;

    if (node.ProductCode == "StarAgent")
    {
        dic["应用在线"] = "/Registry/AppOnline?nodeId=" + nodeId;
        dic["应用发布"] = "/Deployment/AppDeployNode?enable=1&nodeId=" + nodeId;
    }
}
@if (nodeId > 0)
{
    <div class="navbar-collapse text-center">
        <ul class="nav nav-pills" style="margin-bottom: 10px; display: inline-block;float: none;">
            @foreach (var item in dic)
            {
                if (item.Value is IDictionary<String, Object> childs)
                {
                    <li role="presentation" class="dropdown">
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">@item.Key <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            @foreach (var elm in childs)
                            {
                                var url = elm.Value + "";
                                var v = url.Substring(null, "?");
                                if (start.Year > 2000) url += "&dtStart=" + start.ToFullString();
                                if (end.Year > 2000) url += "&dtEnd=" + end.ToFullString();
                                <li role="presentation" class="@(path.EqualIgnoreCase(v)?"active":"")">
                                    <a href="@url">@elm.Key</a>
                                </li>
                            }
                        </ul>
                    </li>
                }
                else
                {
                    var url = item.Value + "";
                    var v = url.Substring(null, "?");
                    if (start.Year > 2000) url += "&dtStart=" + start.ToFullString();
                    if (end.Year > 2000) url += "&dtEnd=" + end.ToFullString();
                    <li role="presentation" class="@(path.EqualIgnoreCase(v)?"active":"")">
                        <a href="@url">@item.Key</a>
                    </li>
                }
            }
        </ul>
    </div>
}